{extend name="common/base" /}
{block name="body"}
<style>
    .order-input{width:30px;text-align:center;}
</style>
<form action="" class="layui-form" method="get">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">标题：</label>
            <div class="layui-input-block">
                <input type="text"
                       name="title"
                       value="{$post.title}"
                       placeholder="请输入标题" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn layui-btn-sm layui-btn-normal">
                    <i class="layui-icon">&#xe615;</i>
                    搜索</button>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <div class="layui-input-block">
                <a href="{:url('news/add')}" class="layui-btn layui-btn-sm layui-btn-normal"  >添加</a>
            </div>
        </div>
        <!--<div class="layui-inline">
            <div class="layui-input-block">
                <button type="button" class="layui-btn layui-btn-normal" id="test1">
                    <i class="layui-icon">&#xe67c;</i>导入
                </button>
            </div>
        </div>-->
    </div>
</form>
<div>
    <form class="layui-form" action="" style="padding: 0px 10px 0px 10px;">
        <table class="layui-table" lay-skin="line">
            <colgroup>
                <col width="80px;">
                <col>
                <col width="90px;">
                <col width="180px;">
                <col>
                <col width="140px;">
            </colgroup>
            <thead>
            <tr>
                <th>序号</th>
                <th>标题</th>
                <th>图片</th>
                <th>更新时间</th>
                <th>评论</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            {volist name="data" id="v"}
            <tr>
                <td><input class="order-input"
                           format-id="{$v.id}"
                           format-order-id="{$v.order_id}"
                           type="text"
                           value="{$v.order_id}"></td>
                <td title="{$v['title']}">{$v.title}</td>
                <td>
                    <div  style="padding: 1px; border: #e6e6e6 solid 1px; width:35px; float: left; ">
                        <img class="form_logo" src="{$v.pic}" width="35" height="35">
                    </div>
                </td>
                <td>{$v.update_time}</td>
                <td>
                    <a href="{:url('comment/index',['type'=>'news','id'=>$v.id])}"
                       class="layui-btn layui-btn-sm layui-btn-normal">查看</a>
                </td>
                <td>
                    <a href="{:url('news/edit',['id'=>$v.id])}"
                       class="layui-btn layui-btn-sm layui-btn-normal">修改</a>
                    <a href="javascript:;"
                       class="layui-btn layui-btn-sm layui-btn-danger" onclick="aa('{$v.id}')">删除</a>
                </td>
            </tr>
            {/volist}
            </tbody>
        </table>
    </form>
    {$page|raw}
</div>
<script>
    layui.use('laydate', function() {
        var laydate = layui.laydate;
        laydate.render({
            elem: '#rhaphp-time1'
            ,type: 'datetime'
            ,range: '到'
            ,format: 'yyyy-M-d'
        });
    })
    layui.use('form', function(){
        var $ = layui.jquery, form = layui.form;
    });
    // 排序
    $('.order-input').blur(function(){
        var id = $(this).attr('format-id');
        var order_id = $(this).val();
        var old_order_id = $(this).attr('format-order-id');
        if (old_order_id != order_id) {
            $.post("{:url('news/saveOrderId')}",{id: id, order_id: order_id},function (res) {
                if(res.status=='0'){
                    layer.msg(res.msg);
                }
                if(res.status=='1'){
                    layer.msg(res.msg);
                }
            })
        }

    });
    function aa(id)
    {
        layer.confirm('确定删除吗？',{btn:['确定','取消']},function(res){
            $.post("{:url('news/del')}",{id:id},function (res) {
                if(res.status=='0'){
                    layer.msg(res.msg);
                }
                if(res.status=='1'){
                    layer.msg(res.msg,{time:1000},function () {
                        location.href="{:url('news/index')}";
                    });
                }
            })
        })

    }
    //删除

    // 导入
    layui.use('upload', function(){
        var upload = layui.upload;

        //执行实例
        var uploadInst = upload.render({
            elem: '#test1' //绑定元素
            ,accept : 'file'
            ,url: '/miniapp/news/import' //上传接口
            ,done: function(res){
                //上传完毕回调
                console.log(res)
            }
            ,error: function(){
                //请求异常回调
            }
        });
    });
</script>
{/block}